﻿Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
Imports Microsoft.Office.Interop




Public Class StatisticTech

    Private dataAdapter As New OleDbDataAdapter
    Private bindingSource1 As New BindingSource()

    Private Sub StatisticTech_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        My.Settings.StatisticTechSize = Me.Size
        My.Settings.StatisticTechPos = Me.Location
    End Sub

    Private Sub StatisticTech_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Size = My.Settings.StatisticTechSize
        FormPos(My.Settings.StatisticTechPos)
        Me.Location = My.Settings.StatisticTechPos


        Me.DataGridView1.DataSource = Me.bindingSource1

        Dim q As String
        q = ControlChars.Quote
        GetData("select EAEMNM, EATECH from CEAEMP ORDER by EAEMNM asc")



    End Sub

    Function GetData(ByVal selectCommand As String)

        Try

            Dim ConCM As OleDb.OleDbConnection
            ConCM = New OleDb.OleDbConnection(My.Settings.M3Connect)
            ConCM.Open()

            Dim cmd As New OleDbCommand(selectCommand, ConCM)

            Me.dataAdapter = New OleDb.OleDbDataAdapter(cmd)
            Dim table As New DataTable
            table.Locale = System.Globalization.CultureInfo.InvariantCulture
            Me.dataAdapter.Fill(table)
            Me.bindingSource1.DataSource = table


            ' Resize the DataGridView columns to fit the newly loaded content.
            Me.DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
        Catch ex As OleDbException

        End Try
        GetData = ""

    End Function

 
    Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
        If e.Button = Windows.Forms.MouseButtons.Right Then

            Me.ContextMenuStrip1.Show()
            Me.ContextMenuStrip1.Left = MousePosition.X
            Me.ContextMenuStrip1.Top = MousePosition.Y


        End If
    End Sub


    Private Sub GetServicesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetServicesToolStripMenuItem.Click
        StatisticsTech("40", "S11", DataGridView1.CurrentRow.Cells(1).Value.ToString, DataGridView1.CurrentRow.Cells(0).Value.ToString, "", "# of opened services")

    End Sub


    Private Sub ShowOpenedServicesInvoicesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowOpenedServicesInvoicesToolStripMenuItem.Click
        StatisticsTech("45", "S11", DataGridView1.CurrentRow.Cells(1).Value.ToString, DataGridView1.CurrentRow.Cells(0).Value.ToString, "", "# of opened service invoices")

    End Sub

    Private Sub ShowMaintenenceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowMaintenenceToolStripMenuItem.Click
        StatisticsTech("40", "S91", DataGridView1.CurrentRow.Cells(1).Value.ToString, DataGridView1.CurrentRow.Cells(0).Value.ToString, "", "# of opened maintenances")

    End Sub

    Private Sub ShowOpenedServicesInvoicesToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowOpenedServicesInvoicesToolStripMenuItem1.Click
        StatisticsTech("45", "S91", DataGridView1.CurrentRow.Cells(1).Value.ToString, DataGridView1.CurrentRow.Cells(0).Value.ToString, "", "# of opened maintenance invoices")

    End Sub
End Class